package com.dao.impl;

import com.dao.IUserDao;
import com.pojo.User;
import com.util.DBHelper;

import java.util.ArrayList;

public class UserDaoImpl implements IUserDao {
    private DBHelper db = new DBHelper();

    //根据账号查询用户
    @Override
    public User selectUserByAccount(String account) {
        String sql = "select * from user where account = ?";
        ArrayList<User> list = db.dtQuery(sql, User.class, account);
        return list.size() > 0 ? list.get(0) : null;
    }

    //验证管理员姓名和身份证是否匹配
    @Override
    public boolean checkAdminInfo(String account, String idcardName, String idcardNo) {

        String sql = "select * from user where account = ? and idcardName = ? and idcardNo = ?";
        ArrayList<User> list = db.dtQuery(sql, User.class, account, idcardName, idcardNo);
        return !list.isEmpty();
    }

    // 根据账号更新用户关联的企业ID和名称
    @Override
    public int updateUserEnterprise(String account, Integer enterpriseId, String enterpriseName) {
        String sql = "update user set enterpriseId  = ?,enterpriseName = ? where account = ?";
        return db.dtUpdate(sql, enterpriseId,enterpriseName,account);
    }

    // 更新管理员姓名和身份证号
    @Override
    public int updateAdminInfo(String account, String idcardName, String idcardNo) {
        String sql = "update user set idcardName = ?, idcardNo = ? where account = ?";
        return db.dtUpdate(sql, idcardName, idcardNo, account);
    }
}
